import request from '@/utils/request';

// 获取车辆列表
export const getCars = (params) => {
  console.log('API getCars 被调用，参数:', params); // 添加日志

  // 确保必要参数存在
  const cleanParams = {
    city: params.city,
    status: '可租',
    page: params.page || 1,
    limit: params.limit || 10
  };

  // 添加其他筛选条件（如果有的话）
  if (params.brand) cleanParams.brand = params.brand;
  if (params.type) cleanParams.type = params.type;
  if (params.level) cleanParams.level = params.level;
  if (params.powerType) cleanParams.powerType = params.powerType;
  if (params.seats) cleanParams.seats = params.seats;
  if (params.minPrice) cleanParams.minPrice = params.minPrice;
  if (params.maxPrice) cleanParams.maxPrice = params.maxPrice;

  return request({
    url: '/cars',
    method: 'get',
    params: cleanParams
  });
};

// 获取车辆详情
export function getCarDetail(id) {
  console.log('调用 getCarDetail API，ID:', id);
  return request({
    url: `/cars/${id}`,
    method: 'get'
  });
} 